$(function () {
    $.ajax({
        url:contextPath +"/ctrl/code/loadTree",
        type:'json',
        success: function(data){
            var treeData = data.data;
            $.fn.zTree.init($("#treeDemo"), setting, treeData);
        }
    })
})

function renameNode(event, treeId, treeNode, isCancel) {
    $.ajax({
        url:contextPath +"/ctrl/code/modifyCode",
        data:{"codeId":treeNode.id,"codeName":treeNode.name},
        async: false,
        success: function(data){}
    })
}

function showRemoveBtn(treeId, treeNode) {
    return treeNode.id!=="1";
}
function showRenameBtn(treeId, treeNode) {
    return treeNode.id!=="1";
}


var setting = {
    view: {
        selectedMulti: false
    },
    edit: {
        enable: true,
        editNameSelectAll: true,
        showRemoveBtn: showRemoveBtn,
        showRenameBtn: showRenameBtn
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        onRename: renameNode
    }
};